#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=200000;
const long long inf=0x7ffffffffffff;

long long min(long long a, long long b) {
  return a<b ? a : b;
}

long long max(long long a, long long b) {
  return a>b ? a : b;
}

class SegmentTree {
public:
  long long v[4*maxn+1], mark[4*maxn+1];

  void markDown(int o, int l, int r) {
    if (mark[o]) {
      v[o] += mark[o];
      if (l!=r) {
	mark[o*2] += mark[o];
	mark[o*2+1] += mark[o];
      }
      mark[o] = 0;
    }
  }

  void add(int o, int l, int r, int tl, int tr, long long tv) {
    markDown(o, l, r);
    if (l==tl && r==tr) {
      mark[o] += tv;
      markDown(o, l, r);
    } else {
      int mid=(l+r)/2;
      if (tl<=mid && tr>=l) {
	add(o*2, l, mid, max(tl, l), min(tr, mid), tv);
      }
      if (tl<=r && tr>mid) {
	add(o*2+1, mid+1, r, max(tl, mid+1), min(tr, r), tv);
      }
      markDown(o*2, l, mid);
      markDown(o*2+1, mid+1, r);
      v[o] = max(v[o*2], v[o*2+1]);
    }
  }

  long long get(int o, int l, int r, int tl, int tr) {
    markDown(o, l, r);
    if (l==tl && r==tr) {
      return v[o];
    } else {
      int mid=(l+r)/2;
      long long ret = -inf;
      if (tl<=mid && tr>=l) {
	ret = max(ret, get(o*2, l, mid, max(tl, l), min(tr, mid)));
      }
      if (tl<=r && tr>mid) {
	ret = max(ret, get(o*2+1, mid+1, r, max(tl, mid+1), min(tr, r)));
      }
      return ret;
    }
  }
};

long long calc(long long x, long long a, long long b, long long c, long long d) {
  return a*x*x*x+b*x*x+c*x+d;
}

int main() {
  freopen("min.in", "r", stdin);
  freopen("min.out", "w", stdout);

  static long long x[maxn+1], f[maxn+1], g[maxn+1][2];
  int n;
  long long a, b, c, d;
  scanf("%d %lld %lld %lld %lld", &n, &a, &b, &c, &d);
  for (int i=1; i<=n; i++) {
    scanf("%lld", x+i);
  }

  static SegmentTree sgt;
  int stsize=0;
  g[0][1] = -inf;
  g[0][0] = 0;
  for (int i=1; i<=n; i++) {
    for (; stsize && g[stsize][1]>=x[i]; stsize--) {
      sgt.add(1, 0, n, g[stsize-1][0], g[stsize][0]-1, -calc(g[stsize][1], a, b, c, d));
    }
    sgt.add(1, 0, n, g[stsize][0], i-1, calc(x[i], a, b, c, d));
    g[++stsize][0] = i;
    g[stsize][1] = x[i];
    f[i] = sgt.get(1, 0, n, 0, i-1);
    sgt.add(1, 0, n, i, i, f[i]);
  }

  printf("%lld", f[n]);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
